<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");
require_once("../_inc/_mbFlagProfValue.php");
require_once("profileFunction.php");

$errMsg = "";
$id_profile = sxREQUEST("id_profile");
if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "save"){
	$errMsg .= profileFlagIns();	
}
if(isset($_REQUEST["id"])){
	$id_profile = $_REQUEST["id"];
}
$aFlagProfile = array();
require('../../../app/_inc/aProFlag.php');
foreach($aProFlag as $flg =>$aFlg) {
	foreach($aFlg['val'] as $val => $dv) {
		$aFlagProfile[$flg] = $val;
		break;
	}
}

$descrProfile = "";
if($id_profile != ""){
	//recupero la description del profilo
	$sSQL = "SELECT description FROM profile WHERE id_profile=$id_profile";
	$objSDAO->query($sSQL, "descrPro");	
	if($row = $objSDAO->fetch("descrPro")){
		$descrProfile = $row["description"];
	}
	$sSQL = "SELECT * FROM flag_profile WHERE id_profile=$id_profile";
	$objSDAO->query($sSQL, "selFlag");
	while($row = $objSDAO->fetch("selFlag")){
		$aFlagProfile[$row["flag"]] = $row["val_flag"];
	}
}else{
	$errMsg.= _t("Il profilo non &egrave; definito")."<br>";
}
//output HTML
$aOpz = array("tit2"=>_t("Flag del profilo"), "isReloadable"=>false);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/ajax.js"></script>  
<script language="JavaScript" type="text/javascript">
	function objFrmSave(){
		var errMsg = "";
		var objFrm = document.getElementById("objFrm");
		var objMessArea =  document.getElementById("messArea");
		if(errMsg == ""){
			objFrm.submit();
		}else{
			objMessArea.innerHTML = errMsg;
		}		
	}
</script>
  
<?php
echo(bodyHTML($aOpz));
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
//form inserimento dati
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"profileFlagIns.php\" method=\"POST\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"id_profile\" id=\"id_profile\" value=\"$id_profile\">");
//output comandi
$aCmd = array("ins"=>array("pag"=>"javascript:objFrmSave()",
										"title"=>_t("Salva i flag del profilo"),
										"text"=>_t("salva"),
										"perm"=>"updpro"),
					"back"=>array("pag"=>$objUser->getHistory(0,false),
										"title"=>$objUser->getHistoryText(0),
										"text"=>$objUser->getHistoryText(0))
					);
echo(commandsHTML($aCmd));	
echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan='3'>"._t("Profilo")." ".sxHE($descrProfile)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"tabh01\" width=\"5%\">"._t("flag")."</td>" .
			"<td class=\"tabh01\" width=\"50%\">"._t("description")."</td>" .
			"<td class=\"tabh01\" width=\"45%\">"._t("valori")."</td>" .
		"</tr>\n");
foreach($aProFlag as $flag => $aFlg){
	echo("<tr>");
	echo("<td class=\"text01\" valign='top'>$flag</td>");
	echo("<td class=\"text01\" valign='top'>".sxHE($aProFlag[$flag]['des'])."</td>");
	echo("<td class=\"text01\">");
	foreach($aFlg['val'] as $val => $dv) {
		$chk = ($val == $aFlagProfile[$flag])?'CHECKED':'';
		echo("<input class=\"text01\" type=\"radio\" name=\"value_".$flag."\" value=\"".sxHE($val)."\" $chk>");
		echo("&nbsp;$dv<br>");
	}
	echo("</td></tr>\n");
}
echo("</table>");

echo(commandsHTML($aCmd));
echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
$objSDAO->close();
?>
